package com.allen.study.test_admin;

import de.codecentric.boot.admin.server.config.EnableAdminServer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;

@EnableDiscoveryClient
@EnableAdminServer
@SpringBootApplication
public class TestAdminApplication {

    public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(TestAdminApplication.class, args);
        Environment env = context.getEnvironment();

        // 获取端口号（默认值设置为空字符串避免空指针）
        String port = env.getProperty("server.port", "未配置端口");
        String contextPath = env.getProperty("server.servlet.context-path", "");

        // 打印启动信息
        System.out.println("\n=================================");
        System.out.println("应用启动成功！访问地址: http://localhost:" + port + contextPath);
        System.out.println("=================================");
    }

}
